package br.com.caelum.vraptor.util;


import javax.inject.Inject;

import br.com.caelum.vraptor.AroundCall;
import br.com.caelum.vraptor.Intercepts;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.auth_annotations.Administrador;
import br.com.caelum.vraptor.components.AdmSessioned;
import br.com.caelum.vraptor.controller.IndexController;
import br.com.caelum.vraptor.interceptor.AcceptsWithAnnotations;
import br.com.caelum.vraptor.interceptor.SimpleInterceptorStack;

@Intercepts
@AcceptsWithAnnotations(Administrador.class)
public class Interceptor {
        
        @Inject
        private AdmSessioned admSessioned;
        @Inject
        private Result result;
        
        @AroundCall
        public void intercept(SimpleInterceptorStack stack){
                if(admSessioned.isLogado()){stack.next();System.out.println("Logado");}
                else{
                        result.redirectTo(IndexController.class).index();
                }
        
    }
}